package org.java2me.mobileboxing;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: aterreno
 */
public class Status {
    public final String description;
    public final int rgbColor;
    private final Date createdDate;

    private Status(String description, int rgbColor) {
        this.description = description;
        this.rgbColor = rgbColor;
        this.createdDate = new Date();
    }
    
    public boolean isIdle(){
    	return this.description.equals("Idle");
    }

    public static Status IDLE() {
        return new Status("Idle", 0x000000FF);
    }

    public static Status WORKING() {
        return new Status("Work!", 0x0000FF00);
    }

    public static Status PAUSE() {
        return new Status("Break!", 0x00FF0000);
    }

    public Status Switch() {
        return (this == IDLE() ? WORKING() : IDLE());
    }

    public long getMsecondsSpent() {
        return (new Date().getTime() - createdDate.getTime());
    }

    public long getMillisRemaining(long totalTime) {
        return totalTime - getMsecondsSpent();
    }

    public String getTimeStatus() {
        String result = "";

        if (this.equals(WORKING())) {
            result = DateHelper.printTime(getMillisRemaining(Scheduler.workingPeriodMsecs));
        }           
        else if (this.equals(PAUSE())) {
            result = DateHelper.printTime(getMillisRemaining(Scheduler.pausePeriodMsecs));
        }
        return result;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Status status = (Status) o;

        if (!description.equals(status.description)) return false;

        return true;
    }

    public int hashCode() {
        return description.hashCode();
    }
}


